@extends('admin::layouts.master')
@section('title')
    管理员列表
@endsection
@section('tab')
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5">
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="key_word" value="{{$arr_search['key_word']}}"  placeholder="请输入用户名" autocomplete="off" class="layui-input ">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="phone" value="{{$arr_search['phone']}}"  placeholder="请输入手机号" autocomplete="off" class="layui-input ">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn layui-btn-normal"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                                <a class="layui-btn" onclick="location.reload()">
                                    <i class="layui-icon layui-icon-refresh"></i>
                                </a>
                            </div>
                        </form>
                    </div>

                    <div class="layui-card-body">
                        <button class="layui-btn layui-btn-normal" onclick="xadmin.open('添加管理员','{{route("admin_admin_create")}}',800,600)"><i class="layui-icon"></i>添加</button>

                    </div>
                    <div class="layui-card-body layui_overflow_y">

                        <table class="layui-table layui-form">
                            <thead>
                            <tr>
                                <th>序号</th>
                                <th>ID</th>
                                <th>用户名</th>
                                <th>手机号</th>
                                <th>状态</th>
                                @if($admin_id == 1)
                                <th>操作</th>
                                @endif
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($data as $key=>$value)
                                <tr>
                                    <td>{{$key+1}}</td>
                                    <td>{{$value["id"]}}</td>
                                    <td>{{$value["username"]}}</td>
                                    <td>{{$value["phone"]}}</td>

                                    <td>
                                        @if($admin_id == 1 && $value["id"] != 1)
                                            @if($value["status"] === 1)
                                                <input type="checkbox" name="switch" data_attr='{"id":"{{$value['id']}}","field_name":"status","url":"{{route("admin_admin_change_state")}}"}'  lay-text="开启|停用" lay-filter="change_state" checked="" lay-skin="switch">
                                            @else
                                                <input type="checkbox" name="switch" data_attr='{"id":"{{$value['id']}}","field_name":"status","url":"{{route("admin_admin_change_state")}}"}' lay-text="开启|停用" lay-filter="change_state" lay-skin="switch">
                                            @endif

                                        @else

                                            @if($value["status"] === 1)
                                                已开启
                                            @else
                                                已禁用
                                            @endif
                                        @endif

                                    </td>

                                    <td class="td-manage">
                                        @if($admin_id == 1)
                                       {{--     @if(!empty($value["openid"]))
                                            <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('修改管理员','{{route("admin_admin_edit",["id"=>$value["id"]])}}')" >微信解绑</button>

                                            @endif--}}

                                            {{--超级管理员admin可以修改所有的用户--}}
                                            <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('修改管理员','{{route("admin_admin_edit",["id"=>$value["id"]])}}')" ><i class="layui-icon">&#xe642;</i>修改</button>

                                            {{--超级管理员admin可以删除除自己以外所有的用户--}}
                                        @if($value["id"] != 1)
                                            <button class="layui-btn-danger layui-btn layui-btn-xs ajax_member_del" data-href="{{route('admin_admin_delete',['id'=>$value['id']])}}" data-title="确定删除管理员吗？请谨慎操作" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                                            @else
                                                <button class="layui-btn-disabled layui-btn layui-btn-xs" ><i class="layui-icon">&#xe640;</i>删除</button>

                                            @endif

                                        @else


                                            {{--非超级管理员admin 只能修改自己的信息--}}
                                        @if($value["id"] == $admin_id)
                                                <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('修改管理员','{{route("admin_admin_edit",["id"=>$value["id"]])}}')" ><i class="layui-icon">&#xe642;</i>修改</button>

                                            @else
                                                <button class="layui-btn-disabled layui-btn layui-btn-xs" ><i class="layui-icon">&#xe642;</i>修改</button>

                                            @endif
                                        @endif
                                    </td>
                                </tr>

                            @endforeach
                            @if($page_data['total'] == 0)
                                <tr><td colspan="66" style="text-align: center">暂无数据</td></tr>
                            @endif
                            </tbody>
                        </table>
                    </div>
                    <div class="layui-card-body ">
                        <div class="page">
                            {{$page_link}}
                        </div>
                        <div id="page"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('tab_js')
    <script>
        layui.use(['form'], function () {
            var form = layui.form;

            //监听指定开关-修改状态
            form.on('switch(change_state)',
                function (obj) {
                    change_state(this);
                });

            //监听搜索
            form.on('submit(sreach)',
                function (data) {
                    var $_url = full_url('{{route('admin_admin_index')}}', data.field);
                    location_redirect($_url)
                });
            form.render();
        });
    </script>
@endsection




